<script setup lang="ts">
import liff from '@line/liff';
import { onMounted } from 'vue';
import { ref } from 'vue'

const msg = ref("hello")

onMounted(() => {
  liff.init({
    liffId: '1656453207-WaY0dAzk', // Use own liffId
  }).then(() => {
    let accessToken = liff.getAccessToken();
    console.log(accessToken);
  }).catch((err) => {
    console.log(err);
  });
})

function scanCode() {
  console.log('scanCode');

  liff.scanCodeV2()
    .then((result) => {
      // e.g. result = { value: 'Hello LIFF app!' }
      console.log('result', result);
      msg.value = result.value ? result.value : '-'
    })
    .catch((err) => {
      console.log(err);
    });
}
</script>

<template>
  <main>
    <van-button type="primary" block @click="scanCode">扫码</van-button>
    <div>
      {{ msg }}
    </div>
  </main>
</template>
